 package server.events;

 import client.MapleCharacter;
import client.MapleDisease;
import server.Timer;
import server.life.MobSkillFactory;
import server.maps.MapleMap;
import tools.MaplePacketCreator;

import java.util.concurrent.ScheduledFuture;








 public class MapleSnowball
   extends MapleEvent
 {
/*  14 */   private final MapleSnowballs[] balls = new MapleSnowballs[2];

   public MapleSnowball(int channel, MapleEventType type) {
/*  17 */     super(channel, type);
   }



   public void finished(MapleCharacter chr) {}


   public void unreset() {
/*  26 */     super.unreset();
/*  27 */     for (int i = 0; i < 2; i++) {
/*  28 */       getSnowBall(i).resetSchedule();
/*  29 */       resetSnowBall(i);
     }
   }


   public void reset() {
/*  35 */     super.reset();
/*  36 */     makeSnowBall(0);
/*  37 */     makeSnowBall(1);
   }


   public void startEvent() {
/*  42 */     for (int i = 0; i < 2; i++) {
/*  43 */       MapleSnowballs ball = getSnowBall(i);
/*  44 */       ball.broadcast(getMap(0), 0);
/*  45 */       ball.setInvis(false);
/*  46 */       ball.broadcast(getMap(0), 5);
/*  47 */       getMap(0).broadcastMessage(MaplePacketCreator.enterSnowBall());
     }
   }

   public void resetSnowBall(int teamz) {
/*  52 */     this.balls[teamz] = null;
   }

   public void makeSnowBall(int teamz) {
/*  56 */     resetSnowBall(teamz);
/*  57 */     this.balls[teamz] = new MapleSnowballs(teamz);
   }

   public MapleSnowballs getSnowBall(int teamz) {
/*  61 */     return this.balls[teamz];
   }

   public static class MapleSnowballs
   {
     private final int team;
/*  67 */     private int position = 0;
/*  68 */     private int startPoint = 0;
     private boolean invis = true;
     private boolean hittable = true;
/*  71 */     private int snowmanhp = 7500;
/*  72 */     private ScheduledFuture<?> snowmanSchedule = null;

     public MapleSnowballs(int team_) {
/*  75 */       this.team = team_;
     }

























     public static void hitSnowball(MapleCharacter chr) {
/* 103 */       int team = ((chr.getTruePosition()).y > -80) ? 0 : 1;
/* 104 */       MapleSnowball sb = (MapleSnowball)chr.getClient().getChannelServer().getEvent(MapleEventType.Snowball);
/* 105 */       MapleSnowballs ball = sb.getSnowBall(team);
/* 106 */       if (ball != null && !ball.isInvis()) {
/* 107 */         boolean snowman = ((chr.getTruePosition()).x < -360 && (chr.getTruePosition()).x > -560);
/* 108 */         if (!snowman) {
/* 109 */           int damage = ((Math.random() < 0.01D || ((chr.getTruePosition()).x > ball.getLeftX() && (chr.getTruePosition()).x < ball.getRightX())) && ball.isHittable()) ? 10 : 0;
/* 110 */           chr.getMap().broadcastMessage(MaplePacketCreator.hitSnowBall(team, damage, 0, 1));
/* 111 */           if (damage == 0) {
/* 112 */             if (Math.random() < 0.2D) {
/* 113 */               chr.send(MaplePacketCreator.leftKnockBack());
/* 114 */               chr.send(MaplePacketCreator.enableActions());
             }
           } else {
/* 117 */             ball.setPositionX(ball.getPosition() + 1);

/* 119 */             if (ball.getPosition() == 255 || ball.getPosition() == 511 || ball.getPosition() == 767) {
/* 120 */               ball.setStartPoint(chr.getMap());
/* 121 */               chr.getMap().broadcastMessage(MaplePacketCreator.rollSnowball(4, sb.getSnowBall(0), sb.getSnowBall(1)));
/* 122 */             } else if (ball.getPosition() == 899) {
/* 123 */               MapleMap map = chr.getMap();
/* 124 */               for (int i = 0; i < 2; i++) {
/* 125 */                 sb.getSnowBall(i).setInvis(true);
/* 126 */                 map.broadcastMessage(MaplePacketCreator.rollSnowball(i + 2, sb.getSnowBall(0), sb.getSnowBall(1)));
               }
/* 128 */               chr.getMap().broadcastMessage(MaplePacketCreator.serverNotice(6, "Congratulations! Team " + ((team == 0) ? "Story" : "Maple") + " has won the Snowball Event!"));
/* 129 */               for (MapleCharacter chrz : chr.getMap().getCharactersThreadsafe()) {
/* 130 */                 if ((team == 0 && (chrz.getTruePosition()).y > -80) || (team == 1 && (chrz.getTruePosition()).y <= -80)) {
/* 131 */                   givePrize(chrz);
                 }
/* 133 */                 sb.warpBack(chrz);
               }
/* 135 */               sb.unreset();
/* 136 */             } else if (ball.getPosition() < 899) {
/* 137 */               chr.getMap().broadcastMessage(MaplePacketCreator.rollSnowball(4, sb.getSnowBall(0), sb.getSnowBall(1)));
/* 138 */               ball.setInvis(false);
             }
           }
/* 141 */         } else if (ball.getPosition() < 899) {
/* 142 */           int damage = 15;
/* 143 */           if (Math.random() < 0.3D) {
/* 144 */             damage = 0;
           }
/* 146 */           if (Math.random() < 0.05D) {
/* 147 */             damage = 45;
           }
/* 149 */           chr.getMap().broadcastMessage(MaplePacketCreator.hitSnowBall(team + 2, damage, 0, 0));
/* 150 */           ball.setSnowmanHP(ball.getSnowmanHP() - damage);
/* 151 */           if (damage > 0) {
/* 152 */             chr.getMap().broadcastMessage(MaplePacketCreator.rollSnowball(0, sb.getSnowBall(0), sb.getSnowBall(1)));
/* 153 */             if (ball.getSnowmanHP() <= 0) {
/* 154 */               ball.setSnowmanHP(7500);
/* 155 */               MapleSnowballs oBall = sb.getSnowBall((team == 0) ? 1 : 0);
/* 156 */               oBall.setHittable(false);
/* 157 */               MapleMap map = chr.getMap();
/* 158 */               oBall.broadcast(map, 4);
/* 159 */               oBall.snowmanSchedule = Timer.EventTimer.getInstance().schedule(() -> { oBall.setHittable(true); oBall.broadcast(map, 5); },10000L);



/* 163 */               for (MapleCharacter chrz : chr.getMap().getCharactersThreadsafe()) {
/* 164 */                 if ((ball.getTeam() == 0 && (chr.getTruePosition()).y < -80) || (ball.getTeam() == 1 && (chr.getTruePosition()).y > -80)) {
/* 165 */                   chrz.giveDebuff(MapleDisease.诱惑, MobSkillFactory.getMobSkill(128, 1));
                 }
               }
             }
           }
         }
       }
     }

     public void resetSchedule() {
/* 175 */       if (this.snowmanSchedule != null) {
/* 176 */         this.snowmanSchedule.cancel(false);
/* 177 */         this.snowmanSchedule = null;
       }
     }

     public int getTeam() {
/* 182 */       return this.team;
     }

     public int getPosition() {
/* 186 */       return this.position;
     }

     public void setPositionX(int pos) {
/* 190 */       this.position = pos;
     }

     public void setStartPoint(MapleMap map) {
/* 194 */       this.startPoint++;
/* 195 */       broadcast(map, this.startPoint);
     }

     public boolean isInvis() {
/* 199 */       return this.invis;
     }

     public void setInvis(boolean i) {
/* 203 */       this.invis = i;
     }

     public boolean isHittable() {
/* 207 */       return (this.hittable && !this.invis);
     }

     public void setHittable(boolean b) {
/* 211 */       this.hittable = b;
     }

     public int getSnowmanHP() {
/* 215 */       return this.snowmanhp;
     }

     public void setSnowmanHP(int shp) {
/* 219 */       this.snowmanhp = shp;
     }

     public void broadcast(MapleMap map, int message) {
/* 223 */       for (MapleCharacter chr : map.getCharactersThreadsafe())
       {
/* 225 */         chr.send(MaplePacketCreator.snowballMessage(this.team, message));
       }
     }




     public int getLeftX() {
/* 233 */       return this.position * 3 + 175;
     }

     public int getRightX() {
/* 237 */       return getLeftX() + 275;
     }
   }
 }


/* Location:              C:\PGX\Server.jar!\server\events\MapleSnowball.class
 * Java compiler version: 8 (52.0)
 * JD-Core Version:       1.1.3
 */